// pages/myPages/personalCenter/creditCard/addCreditCard/addCreditCard.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showView: true,
    userNameInput: '',
    userICInput: '',
    userN: '',
    passW: '',
    BankCardOpening:'银行卡开户行',
    proceeds_type: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      proceeds_type: options.proceeds_type
    })
  },
  userNameInput: function (e) {
    this.setData({
      userN: e.detail.value
    })
    this.loginBtnClick();
  },
  userICInput: function (e) {
    this.setData({
      passW: e.detail.value
    })
    this.loginBtnClick();
  },
  loginBtnClick: function () {
    if (this.data.userN.length != 0 && this.data.passW.length != 0) {
      this.setData({
        showView: false
      })
    } else {
      this.setData({
        showView: true
      })
    }
  },
  chooseBank:function(){
    wx.navigateTo({
      url: './bankClass/bankClass'
    })
  },
  getVerifyingCode: function () {
    var that = this
    var payCode = wx.getStorageSync('tempFilePathsPay')
    var currentBank = wx.getStorageSync('currentBank')
    wx.uploadFile({
      url: 'https://wallet.kinlink.cn/api/gathering/add-proceed',
      header: { 'content-type': 'multipart/form-data' },
      method: 'POST',
      filePath: payCode,
      name: 'qrcode',
      formData: {
        'access_token': wx.getStorageSync('createUser').access_token,
        'proceeds_type': that.data.proceeds_type,
        'account': that.data.passW,
        'username': that.data.userN,
        'bank_name': that.data.BankCardOpening
      },
      success: function (res) {
        var str = res.data;
        var obj = JSON.parse(str);
        if (obj.code == 200) {
          if (that.data.showView == false) {
            wx.navigateBack({
              delta: 1
            })
          }
          wx.showToast({
            title: obj.message,
            icon: 'succes',
            duration: 500,
            mask: true
          });
        } else {
          wx.showToast({
            title: obj.message,
            icon: 'succes',
            duration: 1000,
            mask: true
          });
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.setData({
      setLang: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'] : wx.T.locales['en']

    })
    wx.setNavigationBarTitle({
      title: wx.T.locale == "zh-Hans" ? wx.T.locales['zh-Hans'].BankCard : wx.T.locales['en'].BankCard
    })
    var currentBank = wx.getStorageSync('currentBank')
    if (currentBank != '') {
      this.setData({
        BankCardOpening: currentBank
      })
      wx.removeStorageSync('currentBank')
    }
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})